<?php
/**
 * Created by PhpStorm.
 * User: Kevin
 * Date: 2018/9/19
 * Time: 16:34
 */
namespace app\admin\controller;
use think\Db;
class About extends Base
{
    /*
     * 关于我们首页
     */
    public function index(){
        if(request()->isAjax ()){
            extract(input());
            $Nowpage = input('page') ? input('page'):1;
            $limits = input("limit")?input("limit"):10;// 获取总条数;
            $count = Db::name('about')->where('a_id',1)->count();//计算总页面
            $lists = Db::name('about')->where('a_id',1)->page($Nowpage,$limits)->select();
            return json(['code'=>0,'msg'=>'','count'=>$count,'data'=>$lists]);
        }
        return $this->fetch('about/index');
    }

    /*
     * 编辑关于我们
     */
    public function aboutEdit(){
        if(request()->isPost ()){
            extract(input());
            $param['a_update_time'] = date('Y-m-d H:i:s');
            $param['a_logo'] = $layimg;
            $param['a_name'] = $title;
            $param['a_content'] = $remark;
            $res = Db::name('about')
                ->where('a_id',$id)
                ->update($param);
            if($res) {
                return json (['code' => 200 , 'msg' => '修改成功']);
            }else{
                return json(['code'=>100,'msg'=>'修改失败']);
            }
        }
        $data = Db::name('about')
            ->where('a_id',input('id'))
            ->find();
        return $this->fetch('about/about_edit',['data'=>$data]);
    }

    /*
     * 奖励机制
     */
    public function award(){
        if(request()->isAjax ()){
            extract(input());
            $Nowpage = input('page') ? input('page'):1;
            $limits = input("limit")?input("limit"):10;// 获取总条数;
            $count = Db::name('about')->where('a_id',2)->count();//计算总页面
            $lists = Db::name('about')->where('a_id',2)->page($Nowpage,$limits)->select();
            return json(['code'=>0,'msg'=>'','count'=>$count,'data'=>$lists]);
        }
        return $this->fetch('about/award');
    }

    /*
     * 编辑奖励机制
     */
    public function awardEdit(){
        if(request()->isPost ()){
            extract(input());
            $param['a_update_time'] = date('Y-m-d H:i:s');
            $param['a_content'] = $remark;
            $res = Db::name('about')
                ->where('a_id',$id)
                ->update($param);
            if($res) {
                return json(['code'=>200,'msg'=>'修改成功']);
            }else{
                return json(['code'=>100,'msg'=>'修改失败']);
            }
        }
        $data = Db::name('about')->where('a_id',2)->find();
        return $this->fetch('about/award_edit',['data'=>$data]);
    }

    /*
     * 积分规则
     */
    public function integral(){
        if(request()->isAjax ()){
            extract(input());
            $Nowpage = input('page') ? input('page'):1;
            $limits = input("limit")?input("limit"):10;// 获取总条数;
            $count = Db::name('about')->where('a_id',3)->count();//计算总页面
            $lists = Db::name('about')->where('a_id',3)->page($Nowpage,$limits)->select();
            return json(['code'=>0,'msg'=>'','count'=>$count,'data'=>$lists]);
        }
        return $this->fetch('about/integral');
    }

    /*
     * 编辑积分规则
     */
    public function integralEdit(){
        if(request()->isPost ()){
            extract(input());
            $param['a_update_time'] = date('Y-m-d H:i:s');
            $param['a_content'] = $remark;
            $res = Db::name('about')
                ->where('a_id',$id)
                ->update($param);
            if($res) {
                return json(['code'=>200,'msg'=>'修改成功']);
            }else{
                return json(['code'=>100,'msg'=>'修改失败']);
            }
        }
        $data = Db::name('about')->where('a_id',3)->find();
        return $this->fetch('about/integral_edit',['data'=>$data]);
    }

    /*
     * 用户协议
     */
    public function agreement(){
        if(request()->isAjax ()){
            extract(input());
            $Nowpage = input('page') ? input('page'):1;
            $limits = input("limit")?input("limit"):10;// 获取总条数;
            $count = Db::name('about')->where('a_id','in','4,5,6')->count();//计算总页面
            $lists = Db::name('about')->where('a_id','in','4,5,6')->page($Nowpage,$limits)->select();
            return json(['code'=>0,'msg'=>'','count'=>$count,'data'=>$lists]);
        }
        return $this->fetch('about/agreement');
    }

    /*
     * 编辑协议
     */
    public function agreementEdit(){
        if(request()->isPost ()){
            extract(input());
            $param['a_update_time'] = date('Y-m-d H:i:s');
            $param['a_content'] = $remark;
            $res = Db::name('about')
                ->where('a_id',$id)
                ->update($param);
            if($res) {
                return json(['code'=>200,'msg'=>'修改成功']);
            }else{
                return json(['code'=>100,'msg'=>'修改失败']);
            }
        }
        $data = Db::name('about')->where('a_id',4)->find();
        return $this->fetch('about/agreement_edit',['data'=>$data]);
    }
}